package week02

// 704. 二分查找
// https://leetcode-cn.com/problems/binary-search/

func search(nums []int, target int) int {
	var left, right = 0, len(nums)
	for left < right {
		var mid = (right - left) >> 1 + left
		if nums[mid] == target {
			return mid
		} else if nums[mid] > target {
			right = mid
		} else {
			left = mid + 1
		}
	}
	return -1
}
